<?php
	function mysqlquery($string)
	{
		$result = mysql_query($string);
		return $result;	
	}
	@$connection = mysql_pconnect('localhost', 'root', '');
	if(!$connection)
	{
		echo "Không thể kết nối cơ sở dữ liệu, Bạn vui lòng thử lại sau";
		exit;
	}
	mysql_select_db('studial');
	if(isset($_COOKIE['studialuserid']))
	{
		$friendlist = array();
		$userid = $_COOKIE['studialuserid'];
		$result = mysqlquery("select `friends`.`friend_id` from `friends` where `user_id` = '".$userid."';");
		$check_1 = mysql_num_rows($result);
		if($check_1!=0)
		{
			for( $i = 0 ; $i < $check_1 ; $i ++)
			{
				$rows = mysql_fetch_array($result);
				$friendlist[] = $rows['friend_id'];
			}
		}
		$result = mysqlquery("select `friends`.`user_id` from `friends` where `friend_id` = '".$userid."';");
		$check_1 = mysql_num_rows($result);
		if($check_1!=0)
		{
			for( $i = 0 ; $i < $check_1 ; $i ++)
			{
				$rows = mysql_fetch_array($result);
				$friendlist[] = $rows['user_id'];
			}
		}
		
		for( $i = 0 ; $i < count($friendlist) ; $i ++)
		{
			$result = mysqlquery("select * from `users` where `users`.`id` = '".$friendlist[$i]."';");
			mysql_fetch_array($result);
			echo "<td>";
			echo "<a href=\"../users/homeboard.php?id=".$rows['id']."\"><img class=\"friendphoto\" src=\"../images/photo.jpg\" /><div class=\"friendname\">";
			echo $rows['firstname']." ".$rows['lastname'];
			echo "</a>";
			echo "</td>";
		}
	}

?>